from . import app
from flask import render_template, request, flash
from app.utils import ZitchGhost


@app.route('/', methods=["POST", "GET"])
def root():
    """
    根目录
    """
    if request.method == 'POST':
        recvForm = request.form
        zg = ZitchGhost()
        for k, v in enumerate(recvForm):
            if hasattr(zg, v.lower()):
                setattr(zg, v.lower(), int(recvForm.get(v)))
            else:
                pass
        result = zg.guessGhost()
        if len(result) == 0:
            flash("根本没有这种鬼！")
            return render_template('guessGhost.html')
        elif len(result) == 1:
            return render_template("getResult.html", ghostList=result)
        else:
            return render_template("getResult.html", ghostList=result)
    else:
        return render_template('guessGhost.html')
